<?php
    $this->head('css', 'assets/admin_home');
    $this->head('js',  'assets/admin_home');
?>
<h1>Početna strana</h1>

<p><?= $this->link('+Novi slajd', '/admin_home/create') ?><span id="update-positions">
    | <?= $this->link('Sačuvajte redosled', '/admin_home/update_positions', array(
        'onclick' => 'updatePositionsHref();'
    )) ?>
</span></p>

<ul class="slideshow">
    <? foreach($slideshow as $slide): ?>
    <li value="<?= $slide->id ?>">
        <span class="sort-handle">sort</span>

        <?= $this->img("slideshow/{$slide->image}", $slide->title, array('width' => 200)) ?>
        
        <?= $this->link('edit', "/admin_home/edit/{$slide->id}", array(
            'class' => 'edit'
        )) ?>        
        <?= $this->link('delete', "/admin_home/delete/{$slide->id}", array(
            'confirm' => 'Da li želite da obrišete slajd?',
            'class'   => 'delete'
        )) ?>
    </li>
    <? endforeach ?>
</ul>

<script type="text/javascript">
function updatePositionsHref() {
    var a = $('#update-positions a');
    var pos = '';
    $('.slideshow > li').each(function(index){
        pos += this.value +';'+ index+'/';
    });
    a.attr('href', '/admin_home/update_positions/' + pos);
}
</script>